package com.everflourish.yeah100.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.everflourish.yeah100.R;
import com.everflourish.yeah100.entity.statistics.StudentScoreInfo;
import com.everflourish.yeah100.ui.MyHScrollView;
import com.everflourish.yeah100.utils.constant.StudentStatus;

import java.util.List;

/**
 * 作者：Created by liqisi on 2016/7/6.
 * 时间：2016/7/6
 */
public class FragmentTeacherGradeAdapter extends RecyclerView.Adapter<FragmentTeacherGradeAdapter.TeacherGradeViewHolder> {

    private LayoutInflater mInflater;
    private List<StudentScoreInfo> mList;
    private Context mContext;
    private List<MyHScrollView> myHScrollViews;


    public FragmentTeacherGradeAdapter(Context mContext, List<MyHScrollView> myHScrollViews,
                                       List<StudentScoreInfo> mList) {
        this.mList = mList;
        this.mContext = mContext;
        this.myHScrollViews = myHScrollViews;
        mInflater = LayoutInflater.from(mContext);
    }

    @Override
    public TeacherGradeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_statistics_teacher_grade, parent, false);
        TeacherGradeViewHolder viewHolder = new TeacherGradeViewHolder(view);
        myHScrollViews.add(viewHolder.myHScrollView);
        viewHolder.myHScrollView.setMyHScrollViews(myHScrollViews);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(TeacherGradeViewHolder holder, int position) {
        StudentScoreInfo studentScoreInfo = mList.get(position);
        holder.mStudentNo.setText(studentScoreInfo.getStudentNo());
        holder.mStudentName.setText(studentScoreInfo.getStudentName());
        if (studentScoreInfo.getStatus().equals(StudentStatus.I.text)
                || studentScoreInfo.getStatus().equals(StudentStatus.C.text)) {
            holder.mStudentScore.setText(studentScoreInfo.getScore());
            holder.mStudentClassRank.setText(studentScoreInfo.getClassRanking());
            holder.mStudentTotalRank.setText(studentScoreInfo.getGradeRanking());
        } else {
            holder.mStudentScore.setText("--");
            holder.mStudentClassRank.setText("--");
            holder.mStudentTotalRank.setText("--");
        }
        holder.mStudentClass.setText(studentScoreInfo.getClassName());
        if ((position + 1) % 2 == 0) {  // 双
            holder.mItemLl.setBackgroundColor(mContext.getResources()
                    .getColor(R.color.e_student_item_single));
        } else { // 单
            holder.mItemLl.setBackgroundColor(mContext.getResources()
                    .getColor(R.color.e_student_item_double));
        }
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class TeacherGradeViewHolder extends RecyclerView.ViewHolder {

        private TextView mStudentName;
        private TextView mStudentNo;
        private TextView mStudentClass;
        private TextView mStudentScore;
        private TextView mStudentClassRank;
        private TextView mStudentTotalRank;
        private MyHScrollView myHScrollView;
        private LinearLayout mItemLl;

        public TeacherGradeViewHolder(View itemView) {
            super(itemView);
            mStudentName = (TextView) itemView.findViewById(R.id.item_t_student_name);
            mStudentNo = (TextView) itemView.findViewById(R.id.item_t_student_no);
            mStudentClass = (TextView) itemView.findViewById(R.id.item_t_class);
            mStudentScore = (TextView) itemView.findViewById(R.id.item_t_score);
            mStudentClassRank = (TextView) itemView.findViewById(R.id.item_t_class_rank);
            mStudentTotalRank = (TextView) itemView.findViewById(R.id.item_t_total_rank);
            myHScrollView = (MyHScrollView) itemView.findViewById(R.id.item_t_title_mhv);
            mItemLl = (LinearLayout) itemView.findViewById(R.id.teacher_grade_ll);
        }
    }
}
